home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Numerical / Lib / Matrix.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  767 b   |  30 lines

  1. __id__ = """
  2. $Id: //depot/LLNLDistribution/Numerical/Lib/Matrix.py#8 $
  3. """[1:-1]
  4. import string
  5. __version__ = int(__id__[string.index(__id__, '#')+1:-1])
  6.  
  7. from UserArray import UserArray, asarray
  8. from Numeric import matrixmultiply
  9.  
  10. class Matrix(UserArray):
  11.     def __mul__(self, other):
  12.     return self._rc(matrixmultiply(self.array, asarray(other)))
  13.  
  14.     def __rmul__(self, other):
  15.     return self._rc(matrixmultiply(asarray(other), self.array))
  16.  
  17.     def __pow__(self, other):
  18.     raise TypeError, "x**y not implemented for matrices x"
  19.  
  20.     def __rpow__(self, other):
  21.     raise TypeError, "x**y not implemented for matrices y"
  22.  
  23.  
  24. if __name__ == '__main__':
  25.     from Numeric import *
  26.     m = Matrix( [[1,2,3],[11,12,13],[21,22,23]])
  27.     print m*m
  28.     print m.array*m.array
  29.     print transpose(m)
  30.